<?php
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';

$express_types=model('jy_weishop/model')->express_types();
if($_RQ['op']=='main' || $_RQ['op']=='tpl01'){
	$id=intval($_RQ['id']);
	$id=intval($_RQ['id']);
	$item=model('jy_weishop/order')->get_order($id);
	$item['api_data']=json_decode($item['api_data'],truer);
	$peigoods=$item['api_data']['peiinfo']['goods'];
	$allwfee=0;
	$allwfee2=0;
	$allpi=0;
	$goodsmianji=0;
	foreach($peigoods as $k=>&$gv){
		$goodsinfo=pdo_get('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$gv['goodsid']));
		$api_data=json_decode($goodsinfo['api_data'],true);
		$gv['title']=$goodsinfo['title'];
		$gv['price']=$goodsinfo['price'];
		$gv['goodssn']=$api_data['sn'];
		$gv['wfee']=$api_data['wfee'];
		$gv['onewfee']=price($api_data['wfee']/$gv['mianji']);
		$allpi +=$api_data['pi'];
		$allwfee +=$gv['wfee'];
		$allwfee2 +=$api_data['wfee2'];
		$goodsmianji +=$gv['mianji'];
	}
	$item['allpi']=$allpi;
	$item['allwfee']=$allwfee;
	$item['allwfee2']=$allwfee2;
	$item['goodsmianji']=$goodsmianji;
	$item['peigoods']=$peigoods;
	if($item['api_data']['peiinfo']['waijiid']){
		$waiji=array();
		$goodsinfo=pdo_get('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['api_data']['peiinfo']['waijiid']));
		$api_data=json_decode($goodsinfo['api_data'],true);
		$peibi=$api_data['wfee']/$allwfee;
		$waiji[]=array(
			'title'=>$goodsinfo['title'],
			'price'=>$goodsinfo['price'],
			'goodssn'=>$api_data['sn'],
			'total'=>1,
			'wfee'=>$api_data['wfee'],
			'peibi'=>price($peibi),
		);
	}
	$item['waiji']=$waiji;
	$kongjian=$item['api_data']['peiinfo']['kongjian'];
	foreach($kongjian as $k=>&$gv){
		$goodsinfo=pdo_get('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$gv['goodsid']));
		$api_data=json_decode($goodsinfo['api_data'],true);
		$gv['title']=$goodsinfo['title'];
		$gv['price']=$goodsinfo['price'];
		$gv['goodssn']=$api_data['sn'];
	}
	$item['kongjian']=$kongjian;
	$item['status_title']=$this->order_status[$item['status']];
	$paytype=array('wechat'=>'微信支付','credit'=>'余额支付','hdfk'=>'货到付款');
	$ispay=array('0'=>'未支付','1'=>'已支付');
	$item['paytype']=$paytype[$item['paytype']]?$paytype[$item['paytype']]:'未支付';
	$item['ispay']=$ispay[$item['ispay']];
	$member=model('core/member')->detail($item['mid'],array('nickname','avatar','mobile'));
	$item=array_merge($member,$item);
	$item['address']=json_decode($item['address'],true);
	$item['addressinfo']=model('core/member')->get_address_str($address);
	$item['createtime']=$item['createtime']?date('Y-m-d H:i:s',$item['createtime']):'';
	$item['payime']=$item['payime']?date('Y-m-d H:i:s',$item['payime']):'';
	$item['sendtime']=$item['sendtime']?date('Y-m-d H:i:s',$item['sendtime']):'';
	$item['finishtime']=$item['finishtime']?date('Y-m-d H:i:s',$item['finishtime']):'';
	$item['storetitle']=pdo_getcolumn('jy_weishop_store',array('id'=>$item['storeid']),'title')?:'无';
	$goods=pdo_getall('jy_weishop_order_goods',array('uniacid'=>$_SESSION['uniacid'],'orderid'=>$item['id']),array('goodsid','price','total','optionid'));
	$item['orderprice']=$item['price'];
	foreach($goods as $k=>&$gv){
		$goodsinfo=pdo_get('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$gv['goodsid']));
		$gv['api_data']=json_decode($goodsinfo['api_data'],true);
		$goodsinfo['title']=str_replace(',',' ',$goodsinfo['title']);
		$gv['title']=$goodsinfo['title'];
		$gv['goodssn']=$goodsinfo['goodssn'];
		$gv['productsn']=$goodsinfo['productsn'];
		$gv['subtitle']=$goodsinfo['subtitle'];
		$gv['unit']=$goodsinfo['unit'];
		$gv['merchtitle']=$item['merchtitle']?:'无';
		//商品规格
		if($gv['optionid']){
				$specs=pdo_getcolumn('jy_weishop_goods_option',array('uniacid'=>$_SESSION['uniacid'],'id'=>$gv['optionid']),'specs');
				$specs=explode("_",$specs);
				foreach($specs as &$spec){
					$spec=pdo_getcolumn('jy_weishop_goods_spec_item',array('uniacid'=>$_SESSION['uniacid'],'id'=>$spec),'title');
				}
				$gv['selespename']=implode("，",$specs);
		}
		$newv['title']=$goodsinfo['title'];
		$newv['goodssn']=$goodsinfo['goodssn']?:'无';
		$newv['productsn']=$goodsinfo['productsn']?:'无';
		$newv['offcode']=$goodsinfo['offcode']?:'无';
		$newv['unit']=$goodsinfo['unit']?:'件';
		$newv['price']=$gv['price'];
		$newv['total']=$gv['total'];
		$newv['selespename']=$gv['selespename'];
		$newv=array_merge($item,$newv);
		$exdata[]=$newv;
	}
	$item['goods'] = $goods;
	$item['commission'] = pdo_get('jy_commission_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$item['mid']));
	$item['agent']=cfc('core')->member_show($item['commission']['agent_id'],'',array('nickname'=>'总店'));
	$item['agentmobile']=$item['agent']['mobile'];
	$item['agentname']=$item['agent']['nickname'];
	$return['item']=$item;
	$return['datime']=date('Y-m-d H:i:s');
	$return['basic']=$this->plugin_setting('basic');
	if($_RQ['op']=='tpl01'){
		$return['htmls']=$this->template_url('store/order/dayin01','','windows');
	}
	exi($return);
}
?>